/*
 * Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
 */
package src.com.bjsxt.height.design014_test;

/**
 * Description:
 *
 * @author wzz
 * @since: 1.0
 * Create Date Time: 2018/10/30 17:01
 * Update Date Time:
 */
public class FutureData implements Data {

    private RealData realData;
    private boolean isReady = false;

    public synchronized  void setRealData(RealData realData){
        //如果已经装载完了就直接返回
        if(isReady){
            return;
        }
        this.realData = realData;
        notify();
    }

    @Override
    public synchronized  String getRequest() {
        //如果没装载好,程序就一直处于阻塞状态
        while (!isReady){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        //装载好直接获取数据
        return this.realData.getRequest();
    }
}
